From: Paul Donald Date: Fri, 3 Oct 2025 14:33:32 +0000 (+0200) Subject: config: refactor parse_leasetime() - branch amount remains same X-Git-Url: http://git.openwrt.org/%22https:/collectd.org//%22/%22https:/collectd.org/%22?a=commitdiff_plain;h=964da13e758c002576ea61181a77da128cde4818;p=project%2Fodhcpd.git config: refactor parse_leasetime() - branch amount remains same Also make 's' value a noop. Signed-off-by: Paul Donald Link: https://github.com/openwrt/odhcpd/pull/225 Signed-off-by: Álvaro Fernández Rojas --- diff --git a/src/config.c b/src/config.c index cfc0af6..8a7a9c3 100644 --- a/src/config.c +++ b/src/config.c @@ -431,18 +431,14 @@ static double parse_leasetime(struct blob_attr *c) { double time = strcmp(val, "infinite") ? strtod(val, &endptr) : UINT32_MAX; if (time && endptr && endptr[0]) { - if (endptr[0] == 's') - time *= 1; - else if (endptr[0] == 'm') - time *= 60; - else if (endptr[0] == 'h') - time *= 3600; - else if (endptr[0] == 'd') - time *= 24 * 3600; - else if (endptr[0] == 'w') - time *= 7 * 24 * 3600; - else - goto err; + switch(endptr[0]) { + case 's': break; /* seconds */ + case 'm': time *= 60; break; /* minutes */ + case 'h': time *= 3600; break; /* hours */ + case 'd': time *= 24 * 3600; break; /* days */ + case 'w': time *= 7 * 24 * 3600; break; /* weeks */ + default: goto err; + } } if (time < 60)